package src.threadlocal;

public class ThreadLocalSecondUsage01 {
    public static void main(String[] args) {
        new ServiceOne().process();
    }
}

class ServiceOne {
    public void process() {
        User user = new User("隔壁老王");
        UserContextHolder.holder.set(user);

        new ServiceTwo().process();
        new ServiceThree().process();
    }
}

class ServiceTwo {
    public void process() {
        User user = UserContextHolder.holder.get();
        System.out.println("ServiceTwo拿到用户名：" + user.getName());
    }
}

class ServiceThree {
    public void process() {
        User user = UserContextHolder.holder.get();
        System.out.println("ServiceThree拿到用户名：" + user.getName());
    }
}

class UserContextHolder {
    public static ThreadLocal<User> holder = new ThreadLocal<>();
}


class User {
    String name;

    public User(String name) {
        setName(name);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
